__author__ = 'seamus and arman'

import unittest
from ChessBoard import *

# <summary>
# Unittests written for checking the method AddTextMove()
# of class ChessBoard.
# </summary>
# <owners>Seamus;Arman</owners>
class TestCanAddTextMove(unittest.TestCase):
  
    def loadMoves(self):
        f = open('moves.txt', 'r')
        moves = []
        for line in f:
            moves.extend((line.rstrip()).split(" "))
        return moves

    # <summary>
    # Creates the chess board, and resets it
    # </summary>
    # <owners>Seamus;Arman</owners>
    def setUp(self):
        self.chessboard = ChessBoard()
        self.chessboard.resetBoard()


    # <summary>
    # Teardown method, assigns chessboard to 'None'
    # </summary>
    # <owners>Seamus;Arman</owners>
    def tearDown(self):
        self.chessboard = None



    # <summary>
    # Test Chessboard printing ability for each row on board, check no errors returned
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testChessBoardRowPrintingWithMultipleMoves(self):
        the_moves = self.loadMoves()
        for move in the_moves:
            self.chessboard.addTextMove(move)
        try:
            self.chessboard.printBoardSingleRow()
            self.assertTrue(True)
        except:
            self.assertTrue(False)

    # <summary>
    # Test Chessboard printing ability for whole board, check no errors returned
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testChessBoardWholePrintingWithMultipleMoves(self):
        the_moves = self.loadMoves()
        for move in the_moves:
            self.chessboard.addTextMove(move)
        try:
            self.chessboard.printBoard()
            self.assertTrue(True)
        except:
            self.assertTrue(False)


    # <summary>
    # Feeding invalid text input - Checking with False flag
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testInvalidTextInput(self):
        move = 'zz0010zz'
        self.assertFalse(self.chessboard.addTextMove(move))


    # <summary>
    # Feeding valid text input - Checking with True flag
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testValidTextInput(self):
        move = 'e2e4'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Feeding no text input, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testNoTextInput(self):
        move = 3
        self.assertRaises(AttributeError, self.chessboard.addTextMove, move)


    # <summary>
    # Test Algebraic Notation input, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testANTextInput(self):
        move = 'e2e4'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Test Standard Algebraic Notation input, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testSANTestInput(self):
        move = 'e2xe4'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Test Long Algebraic Notation input, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testLANTextInput(self):
        move = 'Pe2-e4'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Test Algebraic Notation input with promotion to Queen, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testANPromotionTextInput(self):
        move = 'e2e4=Q'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Test Standard Algebraic Notation input with promotion to Queen, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testSANPromotionTextInput(self):
        move = 'e2xe4=Q'
        self.assertTrue(self.chessboard.addTextMove(move))


    # <summary>
    # Test Long Algebraic Notation input with promotion to Queen, check with attribute error.
    # </summary>
    # <owners>Seamus;Arman</owners>
    def testLANPromotionTextInput(self):
        move = 'Pe2e4=Q'
        self.assertTrue(self.chessboard.addTextMove(move))


if __name__ == "__main__":
    unittest.main()
